"use strict";
exports.__esModule = true;
var generator_1 = require("@babel/generator");
var parser_1 = require("@babel/parser");
var traverse_1 = require("@babel/traverse");
var types_1 = require("@babel/types");
// a+b ==> a-b
var t1 = function (path) {
    if (path.isBinaryExpression({ operator: "+" })) {
        path.replaceWith(types_1.binaryExpression("-", path.node.left, path.node.right));
    }
};
// a/b ==> a*b
var t2 = function (path) {
    if (path.isBinaryExpression({ operator: "/" })) {
        path.replaceWith(types_1.binaryExpression("*", path.node.left, path.node.right));
    }
};
// a==b ==> a===b
var t3 = function (path) {
    if (path.isBinaryExpression({ operator: "==" })) {
        path.replaceWith(types_1.binaryExpression("===", path.node.left, path.node.right));
    }
};
// logger transformer
var t4 = function (path) {
    console.log(path.type);
};
function compose() {
    var trans = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        trans[_i] = arguments[_i];
    }
    return function (path) { return trans.forEach(function (t) { return t(path); }); };
}
var TransformerRunner = /** @class */ (function () {
    function TransformerRunner(t) {
        this.t = t;
    }
    TransformerRunner.prototype.runWithAst = function (node) {
        var transOption = {
            enter: this.t
        };
        traverse_1["default"](node, transOption);
        return node;
    };
    return TransformerRunner;
}());
var runner = new TransformerRunner(compose(t1, 
// t2,  // 随意组合
t3));
var runnerWithLogger = new TransformerRunner(compose(t1, t2, t3, t4));
var from = "const t = (a, b) => console.log(a + b, a == b, a / c)";
console.log(from);
var ast = runner.runWithAst(parser_1.parse(from));
console.log(generator_1["default"](ast).code);
runnerWithLogger.runWithAst(parser_1.parse(from));
